package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.found.common.entity.GlobalVariableParam;
import com.ibeeking.found.common.entity.TenantVariableParam;
import com.ibeeking.gmc.global.api.feign.GlobalVariableFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalVariableFeignFallbackFactory implements FallbackFactory<GlobalVariableFeignClient> {
    @Override
    public GlobalVariableFeignClient create(Throwable throwable) {
        return new GlobalVariableFeignClient() {
            @Override
            public ResponseResult<Boolean> addAndModifyGlobalVariable(@RequestBody GlobalVariableParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存全局变量失败。");
            }

            @Override
            public ResponseResult<Boolean> addAndModifyTenantVariable(@RequestBody TenantVariableParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，保存租户全局变量失败。");
            }

        };
    }
}
